package com.example.demo.controller;

import com.example.demo.pojo.req.SendMessageReq;
import com.example.demo.service.impl.AppServiceImpl;
import com.zkkz.boot.message.pojo.MessageStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @Author：Chan
 * @Package：com.zkkz.boot.mqtt.controller
 * @Project：wisdom-cloud-platform
 * @name：AppController
 * @Date：2023/9/13 18:25
 * @Describe：App应用      发消息
 */
@Slf4j
@RefreshScope
@RestController
@RequestMapping("/mqtt")
@Api(tags = "MQTT发送消息")
public class MqttController {

    @Resource
    private AppServiceImpl appServiceImpl;


    @ApiOperation(value = "发送一条消息")
    @PostMapping("/sendMessage")
    public void sendMessage(@RequestBody @Validated SendMessageReq req) {
        appServiceImpl.sendMessage(req.getTopic(), req.getMessage());
    }

    /**
     * @param topic
     * @param message key:id,value:message的内容
     * @return
     */
    @ApiOperation(value = "批量发送数据")
    public List<MessageStatus> sendMessages(String topic, HashMap<String, String> message) {
        return appServiceImpl.sendMessages(topic, message);
    }

}
